'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 获取军公会科技值
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var async = require('async');
var moment = require('moment');
var unionGroupModel = require('../models/unionGroupModel');
var roleModel = require('../models/roleModel');
var onlineService = require('./onlineService');
var PlayerManager = require('../libs/playerManager');
var unionTechConf = require('../config/unionTechConf.js');
var unionTechType = require('../consts/unionTechType.js');

/**
 * 获取公会科技值
 */
exports.getUnionTechValue = function (player_manager, tech_type, callback) {
    var union_group_model;
    var union_id = 0;
    var tech_value = 0;
    if (!player_manager) {
        console.error('error not unionTech  service player_manager -----');
    }
    async.waterfall(
        [
            function (cb) {
                player_manager.getModel(['role'], cb);
            },

            function (cb) {
                var role_model = player_manager.role;
                union_id = role_model.union_id;
                if (!union_id) {
                    return callback(null, 0);
                }

                unionGroupModel.getById(union_id, cb);
            },
            function (union_model, cb) {
                if (!!union_model) {
                    union_group_model = union_model;
                    tech_value = union_group_model.getTechEff(tech_type);
                }
                cb();
            }
        ],
        function (err) {
            if (!!err) {
                return callback(err, 0);
            }
            callback(null, tech_value);
        }
    );
};

/**
 * 获取公会科技值
 */
exports.getUnionTechEff = function (union_group_model, tech_type) {
    if (!union_group_model) {
        return 0;
    }

    return union_group_model.getTechEff(tech_type);
};

/**
 * 获取公会士兵科技列表
 */
exports.getUnionTechForSoldierEff = function (union_model) {
    var union_list = [];
    if (!!union_model) {
        var tech_type_list = [
            unionTechType.UNION_TECH_201, // 提升全体联盟成员地精士兵的伤害N%
            unionTechType.UNION_TECH_202, // 提升全体联盟成员兽人士兵的伤害N%
            unionTechType.UNION_TECH_203, // 提升全体联盟成员天堂士兵的伤害N%
            unionTechType.UNION_TECH_204, // 提升全体联盟成员地狱士兵的伤害N%
            unionTechType.UNION_TECH_206, // 提升全体联盟成员对地精士兵伤害减免N%
            unionTechType.UNION_TECH_207, // 提升全体联盟成员对兽人士兵伤害减免N%
            unionTechType.UNION_TECH_208, // 提升全体联盟成员对天堂士兵伤害减免N%
            unionTechType.UNION_TECH_209 // 提升全体联盟成员对地狱士兵伤害减免N%
        ];

        _.forEach(tech_type_list, function (tech_type) {
            union_list.push({
                tech_type: tech_type,
                tech_eff: union_model.getTechEff(tech_type)
            });
        });
    }

    return union_list;
};
